home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / Example1 / example1.cpp < prev    next >
C/C++ Source or Header  |  2001-10-08  |  7KB  |  199 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. // ===========================================================================
  30. //
  31. //        NULLSOFT WASABI SDK EXAMPLE PROJECTS
  32. //
  33. //            File:            Example1.cpp
  34. //
  35. //            Purpose:    Setup the Example1 Component class for our example component
  36. //
  37. //            Notes:        A note on the comments in this document:
  38. //
  39. //                                Notes that begin with *** are important notes that everyone
  40. //                                needs to read.  The other comments assist readability or
  41. //                                explain the thinking behind sections of code which may not
  42. //                                be immediately obvious to the novice programmer.
  43. //
  44. //                Or I'm just typing to hear myself clickyclack.  Deal.
  45. //
  46. //                Because Example1 is the first of a string of example
  47. //                projects, there are more useless comments in this
  48. //                set of modules than any others.
  49. //
  50.  
  51.  
  52. //
  53. //  GOOD MORNING, CAMPERS!
  54. //
  55. //    I'm your uncle mig and I'd like to welcome to you Nullsoft's
  56. //        Winamp3.0 SDK Camp!
  57. //
  58. //    The SDK with a difference!  (Never mind the weather)
  59. //
  60. //    When you play with Winamp, EVERYTHING is better!
  61. //
  62.  
  63. //
  64. //    For example1, we're gonna just ignore most of this file and
  65. //    play with the example1Wnd.cpp file (for the most part).
  66. //
  67. //    HOWEVER, there are a handful of things you should know about
  68. //    this file first.  Most specifically, you gotta edit all the
  69. //    "//EDITME" lines.  I'll tag out the info as to what all this
  70. //    stuff does inline with the code there.
  71. //
  72.  
  73. //
  74. // Always start with std.h
  75. #include "../common/std.h"
  76. //
  77. #include "example1.h"            //EDITME
  78. #include "resource.h"
  79. #include "example1wnd.h"  //EDITME
  80. //
  81. #include "../common/xlatstr.h"
  82.  
  83. #include "../studio/services/servicei.h"     // For the service template.
  84. #include "../studio/services/svc_wndcreate.h"
  85.  
  86. #include "../common/SimpleWndCreate.h"
  87.  
  88. static WACNAME wac;
  89. WACPARENT *the = &wac;                                         
  90.  
  91. //  *** You MUST use a unique GUID for your WAC files.
  92. //  
  93. //  Here's where you input the GUID.  A GUID is simply a REALLY big random
  94. //  number that lets the rest of the world uniquely identify you (oh yah,
  95. //  guess what "GUID" stands for, bucko?)
  96. //  
  97. //  Otherwise, when you run the app, it'll recognize and load all the WAC
  98. //  files in the WACS folder, but if you report the same GUID as another
  99. //  component, the user'll only be able to control one of them.  
  100. //  
  101. //  If you use the same GUID as some other Winamp3.0 developer, 
  102. //  people will throw rocks at you.  And we'll provide the rocks.
  103. //  
  104. //  Trust me.  This one isn't optional.  Do it, and do it NOW.
  105. //  
  106. //  GUIDGEN.EXE is a utility that comes from Microsoft to help you create
  107. //  GUID numerics.   If you're running Visual Studio, you can find it in
  108. //  the "common\tools" folder.  There's also a helpfile in there name of
  109. //  guidgen.hlp which should get you going with it.  If you need more
  110. //  info, try the MSDN site.
  111. //
  112. //  *** This is MY GUID.  Get your own.   {D4F84EAA-4905-4f62-A209-2735769B07A0}
  113. static const GUID guid =  //EDITME (hint: use guidgen.exe)
  114. { 0xd4f84eaa, 0x4905, 0x4f62, { 0xa2, 0x9, 0x27, 0x35, 0x76, 0x9b, 0x7, 0xa0 } };
  115.  
  116.  
  117. // ===========================================================================
  118. //
  119. // *** WindowCreationServiceObject for this example.
  120. static waServiceT<svc_windowCreate, ThingerWndCreateSvc< Example1Wnd > >  Example1_WndCreateSvc;
  121.  
  122.  
  123. //
  124. //    This "Fortify" stuff is nice happy memory handling and leak detection.
  125. //  You might learn about the specifics of it sometime in the future but,
  126. //    for now, change the output .WAC filenames for your debug and release
  127. //    files here.
  128. WACNAME::WACNAME() {
  129. #ifdef      FORTIFY
  130.   FortifySetName("Example1.wac");        // EDITME
  131.   FortifyEnterScope();
  132. #endif    //FORTIFY
  133.   wnd = NULL;
  134. }
  135.  
  136. WACNAME::~WACNAME() {
  137. #ifdef FORTIFY
  138.   FortifyLeaveScope();
  139. #endif
  140. }
  141.  
  142. //
  143. //  *** You need to supply a human readable string for your name, too.
  144. //
  145. // Ah, well, yes.  There's one problem with GUIDs.  Nobody will be
  146. // able to tell that component {6DC73FE8-6D34-4942-950A-FF2370329BB0}
  147. // is the really kickass breadslicing component you've written for
  148. // Winamp3.0 -- so you gotta actually give it at least a SEMI unique
  149. // name in english, too.
  150. const char *WACNAME::getName() {
  151.   return "Example1 Component"; //EDITME
  152. }
  153.  
  154. GUID WACNAME::getGUID() {
  155.   return guid;
  156. }
  157.  
  158. void WACNAME::onCreate() {
  159.   // *** Do startup stuff here that doesn't require you to have a window yet
  160. }
  161.  
  162. void WACNAME::onRegisterServices() {
  163.   // ***  Register our window creation service here.
  164.   //      If we don't do this, we don't get a window.
  165.   api->service_register(&Example1_WndCreateSvc);
  166.  
  167.   // In this example we use entirely our window class's guid and name.
  168.   api->register_autoPopupGUID(getGUID(), getName());
  169. }
  170.  
  171. void WACNAME::onDestroy() {
  172.   // ***  Deregister our window creation service here.
  173.   //      If we don't do this, we get a memory leak.
  174.   api->service_deregister(&Example1_WndCreateSvc);
  175.   // *** Be sure to delete all your windows etc HERE, not in the destructor
  176.   //     because the API pointer might be invalid in the destructor
  177.   delete wnd; wnd = NULL;
  178.   WACPARENT::onDestroy();
  179. }
  180.  
  181. //
  182. //    *** If the API asks you to make your window, you make your window.
  183. //    NO.
  184. //       QUESTIONS.
  185. //                 ASKED.
  186. //
  187. RootWnd *WACNAME::createWindow(int n, RootWnd *parentWnd) {
  188.   // *** Ignore the integer parameter behind the curtain.
  189.   if (n == 0) {
  190.     // I am the one and true Oz.
  191.     if (wnd != NULL) return NULL;
  192.  
  193.     wnd = new Example1Wnd;
  194.     wnd->init(parentWnd);
  195.     return wnd;
  196.   }
  197.   return 0;
  198. }
  199.